﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;

namespace SindSaude
{
    public partial class ServicosCompleto : System.Web.UI.Page
    {
        private string title = "";
        private string descricao = "";
        private string imagem = "";
        DataTable dt = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            int Servico = 0;
            if (!IsPostBack)
            {
                if (Request.QueryString["a"].ToString() != "0")
                {
                    Servico = Convert.ToInt16(Request.QueryString["a"].ToString());
                    this.carregaGrid(Servico);
                }
                HtmlMeta tag0 = new HtmlMeta();
                tag0.Attributes.Add("property", "og:type");
                tag0.Content = "website";
                Page.Header.Controls.Add(tag0);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    title = dt.Rows[i]["strNome"].ToString().Replace("\n", "");
                    descricao = dt.Rows[i]["StrConteudo"].ToString().Replace("\n", "").Replace("<BR>", "").Replace("\r", "");
                    imagem = dt.Rows[i]["strCaminho_Imagem"].ToString();
                    HtmlMeta tag = new HtmlMeta();
                    tag.Attributes.Add("property", "og:title");
                    tag.Content = title;
                    Page.Header.Controls.Add(tag);
                    HtmlMeta tag1 = new HtmlMeta();
                    tag1.Attributes.Add("property", "og:description");
                    tag1.Content = descricao.Substring(0, 200).ToString() + "...";
                    Page.Header.Controls.Add(tag1);
                    HtmlMeta tag2 = new HtmlMeta();
                    tag2.Attributes.Add("property", "og:image");
                    tag2.Content = imagem;
                    Page.Header.Controls.Add(tag2);

                }

            }
        }
        private void carregaGrid(int _servico)
        {
            SindSaudeCamadas.Dados.servicos servico = new SindSaudeCamadas.Dados.servicos();
            dt = servico.carregaServico(_servico);
            if (dt.Rows.Count > 0)
            {
                string url = HttpContext.Current.Request.Url.AbsoluteUri;
                DataColumn mDataColumn;
                mDataColumn = new DataColumn();
                mDataColumn.DataType = Type.GetType("System.String");
                mDataColumn.ColumnName = "url";
                dt.Columns.Add(mDataColumn);
                dt.Rows[0]["url"] = url.ToString();
                gridServico.DataSource = dt;
                gridServico.DataBind();
                gridServico.GridLines = GridLines.None;
            }
        }
    }
}